<template>
	<view :modelValue="sample" class="container" >
		<!-- 导航栏 -->
		<uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" status-bar left-icon="left" left-text="返回"
			titleStyle="{height: '52px'}" :title="sample.name" @clickLeft="back">
			<block slot="right">
				<view class="city">
					<text  style="font-size: 15px;" @click="confirm">确认流转</text>
				</view>
			</block>
		</uni-nav-bar>
		
		<uni-section title="领样信息" type="line">
			<view class="example">
				<uni-forms  labelPosition="top" >
					<uni-forms-item label="领样部门" labelPosition="top">
						<uni-easyinput v-model="sample.consumeDepName" disabled=""/>
					</uni-forms-item>
					<uni-forms-item label="继续流转人" labelPosition="top">
						<uni-easyinput v-model="sample.foreHandlerName" disabled=""/>
					</uni-forms-item>
					<uni-forms-item label="被流转人" labelPosition="top">
						<uni-easyinput v-model="sample.consumerName" disabled=""/>
					</uni-forms-item>
				</uni-forms>
			</view>
		</uni-section>
		
		<uni-section title="样品基本信息" type="line">
			<view class="example">
				<!-- 基础用法，不包含校验规则 -->
				<uni-forms labelPosition="top" >
					<uni-forms-item label="样品单位" name="department" required>
						<uni-easyinput v-model="sample.department" disabled=""/>
					</uni-forms-item>
					<uni-forms-item label="样品编码" name="code" required>
						<uni-easyinput v-model="sample.code" disabled />
					</uni-forms-item>
					<uni-forms-item label="入库时间">
						<uni-datetime-picker type="datetime" :clear-icon="false" v-model="sample.warehousingTime" disabled />
					</uni-forms-item>
					<uni-forms-item label="样品名称" name="name" required>
						<uni-easyinput v-model="sample.name" disabled=""/>
					</uni-forms-item>
					<uni-forms-item label="规格型号" name="specification" required>
						<uni-easyinput v-model="sample.specification" disabled=""/>
					</uni-forms-item>
					<uni-forms-item label="样品数量" name="number" required>
						<uni-easyinput v-model="sample.number" disabled=""/>
					</uni-forms-item>
					<uni-forms-item label="送样人" name="sender" required >
						<uni-easyinput v-model="sample.sender"disabled="" />
					</uni-forms-item>
				</uni-forms>
			</view>
		</uni-section>
		<uni-section title="样品照片" type="line">
			<view class="example">
				<uni-file-picker limit="3" title="最多选择3张图片" :readonly="true" v-model="sample.imgLists" :auto-upload="true" file-mediatype="image">
				</uni-file-picker>
			</view>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sample: {}
			}
		},
		onLoad(option) {
			// 加载样品存放地点(字典数据，Location)
			this.loadSampleInfo(option.id);
		},
		computed: {},
		methods: {
			loadSampleInfo(sampleId){
				var this_ = this;
				this.$u.api.querySampleInfo(sampleId).then(res=>{
					this_.sample = res.data;
					let imgLists = [];
					//包装图片控件数据
					if(this_.sample.img1)
						imgLists.push({url:this_.sample.img1,name:'img1'})
					if(this_.sample.img2)
						imgLists.push({url:this_.sample.img2,name:'img2'})
					if(this_.sample.img3)
						imgLists.push({url:this_.sample.img3,name:'img3'})
					this_.sample.imgLists=imgLists;
				});
			},
			confirm(){
				var this_ = this; //存储this
				this.$u.api.delegateConfirmSample(this_.sample.id, this_.sample.currentHandler, this_.sample).then(res=>{
					if(res.code==200){
						this_.$u.toast('确认成功');
						this_.back();
					}else{
						this_.$u.toast('调用出错:'+res.msg);
					}
				});
			},
			back() {
				this.backPageRefresh();
			}
		}
	}
</script>

<style>
	.uni-section {
		margin-top: 0px !important;
		background-color: #eee;
	}

	.custom-image-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.example {
		background-color: white;
		padding: 10px 20px 15px 20px;
	}

	.segmented-control {
		margin-bottom: 10px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}
</style>
